package com.liuxvru.project.user.controller;

import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.project.domain.ProjectUserAssignment;
import com.liuxvru.project.service.IProjectUserAssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目与人员分配Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/user/project/projectUserAssignment")
public class UserProjectUserAssignmentController extends BaseController {
    @Autowired
    private IProjectUserAssignmentService projectUserAssignmentService;
    /**
     * 查询项目与人员分配列表
     */
    @GetMapping("/list/{projectId}")
    public TableDataInfo list(@PathVariable("projectId") Long projectId, ProjectUserAssignment projectUserAssignment) {
        startPage();
        projectUserAssignment.setProjectId(projectId);
        List<ProjectUserAssignment> list = projectUserAssignmentService.selectProjectUserAssignmentList(projectUserAssignment);
        return getDataTable(list);
    }
    /**
     * 查询项目与人员分配列表
     */
    @GetMapping("/listAll/{projectId}")
    public AjaxResult listAll(@PathVariable("projectId") Long projectId,ProjectUserAssignment projectUserAssignment) {
        projectUserAssignment.setProjectId(projectId);
        List<ProjectUserAssignment> list = projectUserAssignmentService.selectProjectUserAssignmentList(projectUserAssignment);
        return success(list);
    }

    @PostMapping("/addUser")
    public AjaxResult addUser(@RequestBody ProjectUserAssignment user) {
        return toAjax(projectUserAssignmentService.addUser(user));
    }

    @PostMapping("/upUser")
    public AjaxResult upUser(@RequestBody ProjectUserAssignment user) {
        return toAjax(projectUserAssignmentService.upUser(user));
    }
    @DeleteMapping("/delUser/{id}")
    public AjaxResult delUser(@PathVariable("id") Long id) {
        return toAjax(projectUserAssignmentService.delUser(id));
    }

}
